#include "settingconfig.h"
#include <QJsonDocument>
#include <QJsonObject>
#include <QJsonArray>
#include <QFile>

SettingConfig::SettingConfig()
{
}


QString SettingConfig::downLoadPath()
{
//    return _downLoadPath;
    return stringValueWithKey("downLoadPath");
}

void SettingConfig::setDownLoadPath(const QString &downLoadPath)
{
    setStringValueWithKey("downLoadPath",downLoadPath);
//    _downLoadPath = downLoadPath;
}

QStringList SettingConfig::musicDirs()
{
    QVariant vptr = valueWithKey("musicDirs");
    QStringList list = vptr.toStringList();
    return list;
}

void SettingConfig::addMusicDir(const QString &dir)
{
    QVariant vptr = valueWithKey("musicDirs");
    QStringList list = vptr.toStringList();
    bool isHas = false;
    for(int i=0;i<list.count();i++){
        QString si = list.at(i);
        if(QString::compare(si,dir)==0){
            isHas = true;
            break;
        }
    }
    if(isHas == false){
        list.append(dir);
        QVariant nvptr(list);
        setValueWithKey("musicDirs",nvptr);
    }
}

void SettingConfig::removeMusicDir(const QString &dir)
{
    QVariant vptr = valueWithKey("musicDirs");
    QStringList list = vptr.toStringList();
    int rcount = list.removeAll(dir);
    if(rcount > 0){
        QVariant nvptr(list);
        setValueWithKey("musicDirs",nvptr);
    }
//    bool isHas = false;
//    for(int i=0;i<list.count();i++){
//        QString si = list.at(i);
//        if(QString::compare(si,dir)==0){

//            break;
//        }
//    }
}
